//package com.warren.test;
//
//import java.util.ArrayList;
//import java.util.concurrent.CopyOnWriteArrayList;
//import java.util.concurrent.locks.ReentrantLock;
//
///**
// * @version V1.0
// * @Description: 线程不安全的集合
// * @author: warren
// * @date: 2022/7/19$ 19:24$
// */
//public class UnsafeList {
//    public static void main(String[] args) {
////        ArrayList<String> list = new ArrayList<>();
////        for (int i = 0; i < 10000; i++) {
////            new Thread(() ->{
////                synchronized (UnsafeList.class) {
////                    list.add(Thread.currentThread().getName());
////                }
////            }).start();
////        }
////        try {
////            Thread.sleep(300);
////        } catch (InterruptedException e) {
////            e.printStackTrace();
////        }
////        System.out.println(list.size());
//
//        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
//        for (int i = 0; i < 10000; i++) {
//            new Thread(() ->{
//                list.add(Thread.currentThread().getName());
//            }).start();
//        }
//
//        try {
//            Thread.sleep(300);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        System.out.println(list.size());
//
//        //可重入锁
//       ReentrantLock reentrantLock = new ReentrantLock();
//        try {
//            reentrantLock.lock();
//
//        } finally {
//            reentrantLock.unlock();
//        }
//
//    }
//}
